package com.kaussoft.lolblog.util;

import com.kaussoft.lolblog.action.AbstractAction;
import com.kaussoft.lolblog.action.LoginAction;
import com.kaussoft.lolblog.vo.Account;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;


public class LoginInterceptor implements Interceptor {

	private static final long serialVersionUID = 1L;

	public void destroy() {
    }

    public void init() {
    }

    public String intercept(ActionInvocation invocation) throws Exception {
    	
        Account account = (Account) ((AbstractAction)invocation.getAction()).get(LoginAction.sessionKey);

        if (account == null) {
            return Action.LOGIN;
        }

        AccountThreadLocal.set(account);
        String result = invocation.invoke();
        AccountThreadLocal.set(null);

        return result;
    }
}
